package com.niknik.woody.utils.wunit.junit.runner;

import com.niknik.woody.utils.wunit.junit.rule.LogMonitorRule;
import com.niknik.woody.utils.wunit.junit.rule.MockKeeperRule;
import com.niknik.woody.utils.wunit.junit.rule.TestInfoRule;
import org.junit.rules.ErrorCollector;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestRule;

import java.util.Arrays;
import java.util.Collection;

public class WUnitContext {

  final static WUnitContext INSTANCE = new WUnitContext();

  //TODO: public static final order
  private ExpectedException exMonitor;
  private LogMonitorRule logMonitor;
  private MockKeeperRule mockKeeperRule;
  private ErrorCollector exCollector;
  private TestInfoRule testInfo;

  private WUnitContext() {
  }

  public ExpectedException getExMonitor() {
    return exMonitor;
  }

  public LogMonitorRule getLogMonitor() {
    return logMonitor;
  }

  public TestInfoRule getTestInfo() {
    return testInfo;
  }

  public ErrorCollector getExCollector() {
    return exCollector;
  }

  public MockKeeperRule getMockKeeper() {
    return mockKeeperRule;
  }

  void reset() {
    exMonitor = ExpectedException.none();
    logMonitor = new LogMonitorRule(this);
    mockKeeperRule = new MockKeeperRule(this);
    exCollector = new ErrorCollector();
    testInfo = new TestInfoRule();
  }

  Collection<? extends TestRule> getRules() {
    return Arrays.asList(exMonitor, logMonitor, mockKeeperRule, exCollector, testInfo);
  }
}